<?php

class Pilotage_ManageprojectController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    	$this->_helper->layout()->disableLayout();
    	//$this->_helper->layout()->setLayout("gestionlayout");
    	
    }

    public function addclientsAction()
    {
        // action body
        
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    	
    	$assignform = new Application_Form_Addclientsws();
    	$this->view->form = $assignform;
    	
    	$AFA = new Application_Form_Addclientsws();
    	
    	$AFA->setAction('addclients');
    	
    	$this->view->formulaireAjoutclient = $AFA;
    	
    
    	
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    	
    		if ($AFA->isValid ( $formData ))
    		{
    			$datas = $formData;
    			 
    			 
    			$listclient= new Application_Model_DbTable_PilotListclients();
    			
    			
    			$data=array(
    					"URLWEBSERVICE" => $datas['wsurl'],
    					"WSDLTEXT" => $datas['wsdl'],
    					"LOGIN" => $datas['login'],
    					"PASSWORD" => $datas['motdepasse'],
    					"PREFIX" => $datas['prefixe'],
    					"NOMCLIENT" => $datas['nomclient'],
    					"DESCRIPTION" => $datas['description'],
    					"URLPLATEFORME"=> $datas['URLPLATEFORME']
    					);
    			
    			$listclient->insert($data);
    			$this->_helper->redirector("gestionclient");
    	
    		}
    	}  
    }

    public function affichelistclientsAction()
    {
        // action body
        
    	$listesclients = new Application_Model_Mapper_PilotListclients();
    
    	$listeclient= $listesclients->fetchAllToArray();
    }

    public function addprojectAction()
    {
        // action body
        
    	$this->_helper->layout()->disableLayout();
    	   $this->_helper->layout()->setLayout("gestionlayout");
    	
    	$assignform = new Application_Form_Addproject();
    	$this->view->form = $assignform;
    	 
    	$AFA = new Application_Form_Addproject();
    	 
    	$AFA->setAction('addproject');
    	 
    	$this->view->FormulaireAjoutprojet = $AFA;
    	 
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($AFA->isValid ( $formData ))
    		{
    			$datas = $formData;
    	
    	
    			$listclient= new Application_Model_DbTable_PilotProject();
    			 
    			 
    			$data=array(
    					"NomProjet" => $datas['NomProjet'],
    					"DESCRIPTION" => $datas['description'],
    					
    						
    			);
    			 
    			$listclient->insert($data);
    			$this->_helper->redirector("affichprojet");
    		}
    	}
    }

    public function affichprojetAction()
    {
        // action body
         	
   	
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$header=array(
    			"idPILOT_PROJECT"=>"Identificateur",
    			"NomProjet"=>"Nom du Projet",
    			"DESCRIPTION"=>"Description"
    	);
    	
    	$usermapper= new Application_Model_Mapper_PilotProject();
    	$select=$usermapper->fetchAllToArray();
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    	
    	$this->view->header=$header;
    	
    	$this->view->keyOfData="idPILOT_PROJECT";
    	
    	
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
  	
    }

    public function deleteprojectAction()
    {
        // action body
    $this->_helper->layout()->disableLayout();
    $this->_helper->layout()->setLayout("gestionlayout");
    	
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    	
    	if ($this->_request->isPost())
    	{
    		$formData = $this->_request->getPost ();
    	
    		 print_r($formData);
    		if ($formData['operation']=="oui")
    		{
    			 
    			$modele = new Application_Model_PilotProject();
    			
    			$projectmodel= new Application_Model_DbTable_PilotProject();
    			
    			$projectmodel->delete(array(" idPILOT_PROJECT = ? " => $this->_getParam('id')));
    			
    			$this->_helper->redirector('gestionproject','manageproject');
    		}
    		
    		else
    		{
    		
    			$this->_helper->redirector("gestionproject");
    		}
    		 
    	}
    }

    public function gestionprojectAction()
    {
        // action body
        
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	
    	$header=array(
    			"idPILOT_PROJECT"=>"Id projet d'analyse",
    			"NomProjet"=>"Nom de projet",
    			"DESCRIPTION"=>"Description"
    	);
    	$usermapper= new Application_Model_Mapper_PilotProject();
    	$select=$usermapper->fetchAllToArray();
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(5);
    	$paginator->setCurrentPageNumber($page);
    	
    	$this->view->header=$header;
    	
    	$this->view->keyOfData="idPILOT_PROJECT";
    	
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }

    public function updateprojectAction()
    {
        // action body
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    	 
    	$AFAffich = new  Application_Form_Modifierproject();
    	$AFAffich->setAction('updateproject');
    	$this->view->Formulairemodifierproject = $AFAffich;
    	 
    	if ($this->getRequest()->isPost()) {
    		$formData = $this->getRequest()->getPost();
    		if ($AFAffich->isValid($formData)) {
    			//$id = $AFAffich->getValue('idPILOT_PROJECT');
    			$nommodele = $AFAffich->getValue('NomProjet');
    			$xmttext = $AFAffich->getValue('DESCRIPTION');
    			$albums = new Application_Model_DbTable_PilotProject();
    			 
    			$albums->update(array(
    				//"idPILOT_PROJECT" =>$AFAffich->getValue('idPILOT_PROJECT'),
    					"NomProjet"=>$AFAffich->getValue('NomProjet'),
    					"DESCRIPTION"=>$AFAffich->getValue('DESCRIPTION')),
    					"idPILOT_PROJECT = '".$AFAffich->getValue('idPILOT_PROJECT')."'");
    			 
    			$this->_helper->redirector("gestionproject");
    		} else {
    			$AFAffich->populate($formData);
    		}
    	} else {
    		$id = $this->_getParam('id');
    		if (!empty($id)) {
    			$modele = new Application_Model_DbTable_PilotProject();
    			$data=$modele->fetchRow(" idPILOT_PROJECT = '".$id."'")->toArray();
    			 
    			$AFAffich->populate($data);
    		}
    	}
    }

    public function assignermodeleAction()
    
    {
    		$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    	
    	$AFAffich = new  Application_Form_Assignermodele();
    	$AFAffich->setAction('assignermodele');
    	$this->view->FormulaireAssignmodele = $AFAffich;
    	
    	if (!empty($_POST)) {
    		$formData = $this->getRequest()->getPost();
    		print_r($formData);
    		if ($AFAffich->isValid($formData)) {
    			$checkb = $AFAffich->getValue('idPILOT_MODELANALYSE');
    			 
    			foreach ($checkb as $value){
    				$datas = new Application_Model_DbTable_PilotProjetanalyse();
    					
    				$data=array(
    							
    						"idPILOT_PROJETANALYSE" =>  $this->_getParam("idPILOT_PROJETANALYSE")."_".$value,
    						"PILOT_PROJECT_idPILOT_PROJECT" => $this->_getParam("idPILOT_PROJECT"),
    						"PILOT_LISTCLIENTS_idPILOT_LISTCLIENTS" => $this->_getParam("idPILOT_LISTCLIENTS"),
    						"idPILOT_MODELANALYSE" => $value,
    				);
    	
    				$datas->insert($data);
    			}
    			$this->_helper->redirector('gestionassignemodelprojet');
    		} else {
    			$AFAffich->populate($formData);
    		}
    	}

    }

    public function menugestclientAction()
    {
    	$this->_helper->layout()->disableLayout();
    	//$this->_helper->layout()->setLayout("gestionlayout");
    
    	$AFA = new Application_Form_menugestionclient();
    		
    	$AFA->setAction('menugestclient');
    		
    	$this->view->Formulairemenugestclient = $AFA;
    }

  
    
    public function gestionclientAction()
    {
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
  	
    	 
    	$header=array(
    			"idPILOT_LISTCLIENTS"=>"identificateur",
    			"NOMCLIENT"=>"Nom client",
    			"LOGIN"=>"Login",
    			"LOGIN"=>"Login",
    			"PASSWORD"=>"motdepasse",
    			"URLPLATEFORME"=>"URL Plateforme",
    			"DESCRIPTION"=>"Description",
    			"URLWEBSERVICE"=>"wsurl",
    			"WSDLTEXT"=>"WSDL",
    			"PREFIX"=>"Prefixe"
    	);
    	$usermapper= new Application_Model_Mapper_PilotListclients();
    	$select=$usermapper->fetchAllToArray();
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    	 
    	$this->view->header=$header;
    	 
    	$this->view->keyOfData="idPILOT_LISTCLIENTS";
    	 
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }
    
    
    public function deleteclientAction()
    {
    
    	// action body
    
    	$this->_helper->layout()->disableLayout();
    	
    	
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    	
    	
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    		 
    		if ($formData['operation']=="oui")
    		{
    			 
    			$modele = new Application_Model_PilotListclients();
    			
    			   			 
    			$modele->setIdPILOTLISTCLIENTS($formData['id']);
    			 
    			$modelesmap = new Application_Model_Mapper_PilotListclients();
    			 
    			$modelesmap->delete($modele);
    			
    			$this->_helper->redirector('gestionclient','Manageproject');
    		}
    		
    		else
    		{
    		
    			$this->_helper->redirector("gestionclient");
    		}
    	
    }
    }
    public function updateclientAction()
    {
    	// action body
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$AFAffich = new  Application_Form_updateclient();
    	$AFAffich->setAction('updateclient');
    	$this->view->Formulairemodifierclient = $AFAffich;
    
    	if ($this->getRequest()->isPost()) {
    		$formData = $this->getRequest()->getPost();
    		if ($AFAffich->isValid($formData)) {
    	
    			
    			$albums = new Application_Model_DbTable_PilotListclients();
    
    			$albums->update(array(
    					//"idPILOT_PROJECT" =>$AFAffich->getValue('idPILOT_PROJECT'),
    					"NOMCLIENT"=>$AFAffich->getValue('NOMCLIENT'),
    					"LOGIN"=>$AFAffich->getValue('LOGIN'),
    					"PASSWORD"=>$AFAffich->getValue('PASSWORD'),
    					"DESCRIPTION"=>$AFAffich->getValue('DESCRIPTION'),
    					"WSDLTEXT"=>$AFAffich->getValue('WSDLTEXT'),
    					"URLWEBSERVICE"=>$AFAffich->getValue('URLWEBSERVICE'),
    					"URLPLATEFORME"=> $AFAffich->getValue('URLPLATEFORME'),
    					"PREFIX"=>$AFAffich->getValue('PREFIX')),
    					"idPILOT_LISTCLIENTS = '".$AFAffich->getValue('idPILOT_LISTCLIENTS')."'");
    					
    
    			$this->_helper->redirector("gestionclient");
    		} else {
    			$AFAffich->populate($formData);
    		}
    	} else {
    		$id = $this->_getParam('id');
    		if (!empty($id)) {
    			$modele = new Application_Model_DbTable_PilotListclients();
    			$data=$modele->fetchRow(" idPILOT_LISTCLIENTS = '".$id."'")->toArray();
    
    			$AFAffich->populate($data);
    		}
    	}
    }
    
    public function gestionassignemodelprojetAction()
    {
    	//action body
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    	
    	$header=array(
    			"idPILOT_PROJETANALYSE" =>"ID",
    			"PILOT_PROJECT_idPILOT_PROJECT" =>"ID projet",
    			"PILOT_LISTCLIENTS_idPILOT_LISTCLIENTS" =>"ID client",
    			"idPILOT_MODELANALYSE" =>"ID modele",
    	);
    	
    	$usermapper= new Application_Model_Mapper_PilotProjetanalyse();
    	$select=$usermapper->fetchAllToArray();
    	$page=$this->_getParam('page',1);
    	$paginator = Zend_Paginator::factory($select);
    	$paginator->setItemCountPerPage(3);
    	$paginator->setCurrentPageNumber($page);
    
    	$this->view->header=$header;
    
    	$this->view->keyOfData="idPILOT_PROJETANALYSE";
    
    	Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');
    	$this->view->paginator=$paginator;
    }
    
    public function deleteassignemodelprojetAction()
    {
    	$this->_helper->layout()->disableLayout();
    		
    	$this->view->id = $this->_getParam('id');
    	$this->view->messagedelate= "voulez-vous vraiment supprimer cette enregisterement ?";
    		
    	if ($this->_request->isPost ())
    	{
    		$formData = $this->_request->getPost ();
    
    		if ($formData['operation']=="oui")
    		{
    
    				
    			$activite = new Application_Model_PilotProjetanalyse();
    
    			$activite->setIdPILOTPROJETANALYSE($formData['id']);
    
    			$activites = new Application_Model_Mapper_PilotProjetanalyse();
    
    			$activites->delete($activite);
    
    			$this->_helper->redirector('gestionassignemodelprojet','manageproject');
    		}
    		else
    		{
    			$this->_helper->redirector("gestionassignemodelprojet");
    		}
    	}
    }
    
    public function modifierassignemodelprojetAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    		
    	$AFAffich = new  Application_Form_modifierassignemodelprojet();
    	$AFAffich->setAction($this->_helper->url('gestionassignemodelprojet','manageproject','pilotage'));
    	$this->view->Formulairemodifierassignemodelprojet = $AFAffich;
    		
    	if ($this->getRequest()->isPost()) {
    		$formData = $this->getRequest()->getPost();
    
    		//var_dump($formData);exit;
    		if ($AFAffich->isValid($formData)) {
    
    			$albums = new Application_Model_DbTable_PilotProjetanalyse();
    
    			$albums->update(array(
    					"PILOT_PROJECT_idPILOT_PROJECT"=>$AFAffich->getValue('PILOT_PROJECT_idPILOT_PROJECT'),
    					"idPILOT_MODELANALYSE"=>$AFAffich->getValue('idPILOT_MODELANALYSE'),
    					"PILOT_LISTCLIENTS_idPILOT_LISTCLIENTS"=>$AFAffich->getValue('PILOT_LISTCLIENTS_idPILOT_LISTCLIENTS')),
    					"idPILOT_PROJETANALYSE = '".$AFAffich->getValue('idPILOT_PROJETANALYSE')."'");
    
    			$this->_helper->redirector('gestionassignemodelprojet');
    
    		} else {
    			$AFAffich->populate($formData);
    		}
    	} else {
    		$id = $this->_getParam('id');
    		if (!empty($id)) {
    			$reqcomp = new Application_Model_DbTable_PilotProjetanalyse();
    			$data=$reqcomp->fetchRow("idPILOT_PROJETANALYSE = '".$id."'")->toArray();
    				
    			$AFAffich->populate($data);
    		}
    	}
    }
    
    
    public function modifierAction()
    {
    	// action body
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->layout()->setLayout("gestionlayout");
    
    	$AFAffich = new  Application_Form_updateclient();
    	$AFAffich->setAction('updateclient');
    	$this->view->Formulairemodifierclient = $AFAffich;
    
    	if ($this->getRequest()->isPost()) {
    		$formData = $this->getRequest()->getPost();
    		if ($AFAffich->isValid($formData)) {
    			 
    			 
    			$albums = new Application_Model_DbTable_PilotListclients();
    
    			$albums->update(array(
    					//"idPILOT_PROJECT" =>$AFAffich->getValue('idPILOT_PROJECT'),
    					"NOMCLIENT"=>$AFAffich->getValue('NOMCLIENT'),
    					"LOGIN"=>$AFAffich->getValue('LOGIN'),
    					"PASSWORD"=>$AFAffich->getValue('PASSWORD'),
    					"DESCRIPTION"=>$AFAffich->getValue('DESCRIPTION'),
    					"WSDLTEXT"=>$AFAffich->getValue('WSDLTEXT'),
    					"URLWEBSERVICE"=>$AFAffich->getValue('URLWEBSERVICE'),
    					"URLPLATEFORME"=> $AFAffich->getValue('URLPLATEFORME'),
    					"PREFIX"=>$AFAffich->getValue('PREFIX')),
    					"idPILOT_LISTCLIENTS = '".$AFAffich->getValue('idPILOT_LISTCLIENTS')."'");
    				
    
    			$this->_helper->redirector("gestionclient");
    		} else {
    			$AFAffich->populate($formData);
    		}
    	} else {
    		$id = $this->_getParam('id');
    		if (!empty($id)) {
    			$modele = new Application_Model_DbTable_PilotListclients();
    			$data=$modele->fetchRow(" idPILOT_LISTCLIENTS = '".$id."'")->toArray();
    
    			$AFAffich->populate($data);
    		}
    	}
    }
    
}

